package com.hinnotek.warehouse.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.databinding.DataBindingUtil
import com.hinnotek.warehouse.BR
import com.hinnotek.warehouse.R
import com.hinnotek.warehouse.bean.DialogBean
import com.hinnotek.warehouse.databinding.DialogContentCircle2Binding
import com.hinnotek.warehouse.databinding.DialogContentCircleBinding
import com.hinnotek.warehouse.databinding.DialogRejectLayoutBinding
import com.hinnotek.warehouse.databinding.ItemDialogBinding
import com.lee.common.adapter.binding.SimpleBindingAdapter
import com.lee.common.ext.init
import com.lee.common.widget.BottomStyleDialog
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog


class Dialogs(var context: Context) {

    /**
     * 审核弹出
     */
    fun showCurrency2(
        okClickListener: View.OnClickListener,
        noClickListener: View.OnClickListener
    ) {
        val bottomDialog = BottomStyleDialog(context, R.style.BottomDialogMargin)
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val circleBinding = DataBindingUtil.inflate<DialogContentCircle2Binding>(
            inflater, R.layout.dialog_content_circle2, null, false
        )
        //审核通过
        circleBinding.ok.setOnClickListener {
            okClickListener.onClick(it)
            bottomDialog.dismiss()
        }
        //拒绝
        circleBinding.no.setOnClickListener {
            noClickListener.onClick(it)
            bottomDialog.dismiss()
        }
        //取消
        circleBinding.cancle.setOnClickListener {
            bottomDialog.dismiss()
        }
        bottomDialog.setContentView(circleBinding.root)
        bottomDialog.show()
    }

    /**
     * 拒绝理由
     */
    fun showCurrency5(
        submitClick: View.OnClickListener
    ) {
        val bottomDialog = BottomStyleDialog(context, R.style.BottomDialog)
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val circleBinding = DataBindingUtil.inflate<DialogRejectLayoutBinding>(
            inflater, R.layout.dialog_reject_layout, null, false
        )
        //审核通过
        circleBinding.submit.setOnClickListener {
            submitClick.onClick(it)
            bottomDialog.dismiss()
        }
        bottomDialog.setContentView(circleBinding.root)
        bottomDialog.show()
    }

    /**
     * 拒绝理由
     */
    fun showCurrency4(
        submitClick: (String) -> View.OnClickListener
    ) {
        val bottomDialog = BottomStyleDialog(context, R.style.BottomDialog)
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val circleBinding = DataBindingUtil.inflate<DialogRejectLayoutBinding>(
            inflater, R.layout.dialog_reject_layout, null, false
        )
        //审核通过
        circleBinding.submit.setOnClickListener{
            submitClick.invoke(circleBinding.editTextTextPersonName2.text.toString()).onClick(it)
            bottomDialog.dismiss()
        }
        bottomDialog.setContentView(circleBinding.root)
        bottomDialog.show()
    }


    fun showCurrency3(
        count: String,okClickListener: MaterialDialog.SingleButtonCallback
    ) {
        MaterialDialog.Builder(context)
            .iconRes(com.lee.common.R.drawable.icon_tip)
            .title("提示")
            .content(count)
            .positiveText("确定")
            .onPositive { dialog, which ->
                dialog.dismiss()
                okClickListener.onClick(dialog, which)
            }
            .negativeText("取消")
            .onNegative { dialog, which ->
                dialog.dismiss()
            }
            .show()
    }


    fun showCurrency() {
        val adapter: SimpleBindingAdapter<DialogBean, ItemDialogBinding>
        val dialogList = arrayListOf<DialogBean>().apply {
            this.add(DialogBean("审核通过"))
            this.add(DialogBean("审核拒绝"))
            this.add(DialogBean("审核拒绝"))
            this.add(DialogBean("审核拒绝"))
            this.add(DialogBean("审核拒绝"))
        }
        val bottomDialog = BottomStyleDialog(context, R.style.BottomDialog)
        val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val circleBinding = DataBindingUtil.inflate<DialogContentCircleBinding>(
            inflater, R.layout.dialog_content_circle, null, false
        )
        adapter = SimpleBindingAdapter(R.layout.item_dialog, dialogList, BR.dialog)

        circleBinding.itemRecycler.init()
        circleBinding.itemRecycler.adapter = adapter
        adapter.setNewInstance(dialogList)
        bottomDialog.setContentView(circleBinding.root)
        bottomDialog.show()
    }
}